home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swags_z.zip / STRINGS.SWG / 0064_HEX Strings.pas < prev    next >
Pascal/Delphi Source File  |  1993-11-21  |  992b  |  39 lines

  1. {
  2. From: GREG ESTABROOKS
  3. Subj: Writing hexes
  4. Is there a quick and easy way to convert an integer to a hex number?
  5. example, if I have an integer num1:=32;  is there a way to print "20h
  6. screen?
  7. }
  8.  
  9. CONST
  10.      HexList :ARRAY[0..15] OF CHAR ='0123456789ABCDEF';
  11.  
  12. FUNCTION HiWord( Long :LONGINT ) :WORD; ASSEMBLER;
  13.                       { Routine to return high word of a LongInt.       }
  14. ASM
  15.   Mov AX,Long.WORD[2]              { Move High word into AX.            }
  16. END;
  17.  
  18. FUNCTION LoWord( Long :LONGINT ) :WORD; ASSEMBLER;
  19.                       { Routine to return low word of a LongInt.        }
  20. ASM
  21.   Mov AX,Long.WORD[0]              { Move low word into AX.             }
  22. END;
  23.  
  24.  
  25. FUNCTION BHex( V :BYTE ) :STRING;
  26. BEGIN
  27.   BHex := HexList[V Shr 4] + HexList[V Mod 16];
  28. END;
  29.  
  30. FUNCTION WHex( V :WORD ) :STRING;
  31. BEGIN
  32.   WHex := Bhex(Hi(V)) + BHex(Lo(V));
  33. END;
  34.  
  35. FUNCTION LHex( Long :LONGINT ) :STRING;
  36. BEGIN
  37.   LHex := WHex(HiWord(Long))+WHex(LoWord(Long));
  38. END;
  39.